package com.lsa.letcode.the15.the3sum;

public class Mm2 {
	public static void main(String[] args) {
		int[] arr = new int[]{
				-4,  -1,  -1,   0,   1,   2
//				-15, -15, -15, -15, -14, -14, -13, -13, -13, -13, -13, -13, -12, -12, -11, -11, -10, -10, -10,  -9,  -9,  -9,  -9,  -9,  -9,  -8,  -7,  -6,  -6,  -6,  -6,  -6,  -6,  -6,  -5,  -5,  -4,  -4,  -4,  -4,  -4,  -4,  -4,  -4,  -3,  -3,  -3,  -3,  -3,  -3,  -2,  -2,  -2,  -2,  -2,  -1,  -1,  -1,   0,   1,   1,   1,   2,   3,   3,   3,   4,   4,   5,   5,   6,   6,   6,   7,   7,   7,   7,   8,   8,   8,   8,   9,   9,   9,  10,  10,  10,  11,  11,  11,  11,  11,  11,  12,  12,  12,  12,  13,  13,  13,  13,  13,  14,  14,  14,  14,  14
	//	 0,	 1,	 2,	 3,	4, 5, 6, 7, 8, 9, 10 		
//		-2, -2, -1, -1, 1, 1, 1, 1, 2, 3, 4
		};
		//  
		// (3,4),(2,4), (1[6],4),(1[4],4),(-1[3],4),(-1[2],4),(-2[1],4),(-2[0],4)
		
//		  0,   1,   2,   3,   4,   5,   6,   7,   8,   9,  10,  11,  12,  13,  14,  15,  16,  17,  18,  19,  20,  21,  22,  23,  24,  25,  26,  27,  28,  29,  30,  31,  32,  33,  34,  35,  36,  37,  38,  39,  40,  41,  42,  43,  44,  45,  46,  47,  48,  49,  50,  51,  52,  53,  54,  55,  56,  57,  58,  59,  60,  61,  62,  63,  64,  65,  66,  67,  68,  69,  70,  71,  72,  73,  74,  75,  76,  77,  78,  79,  80,  81,  82,  83,  84,  85,  86,  87,  88,  89,  90,  91,  92,  93,  94,  95,  96,  97,  98,  99, 100, 101, 102, 103, 104, 105, 106, 
//		-15, -15, -15, -15, -14, -14, -13, -13, -13, -13, -13, -13, -12, -12, -11, -11, -10, -10, -10,  -9,  -9,  -9,  -9,  -9,  -9,  -8,  -7,  -6,  -6,  -6,  -6,  -6,  -6,  -6,  -5,  -5,  -4,  -4,  -4,  -4,  -4,  -4,  -4,  -4,  -3,  -3,  -3,  -3,  -3,  -3,  -2,  -2,  -2,  -2,  -2,  -1,  -1,  -1,   0,   1,   1,   1,   2,   3,   3,   3,   4,   4,   5,   5,   6,   6,   6,   7,   7,   7,   7,   8,   8,   8,   8,   9,   9,   9,  10,  10,  10,  11,  11,  11,  11,  11,  11,  12,  12,  12,  12,  13,  13,  13,  13,  13,  14,  14,  14,  14,  14,
		
//		   0,   1,   2,   3,   4,   5, 
//		  -4,  -1,  -1,   0,   1,   2,
		
		int j = arr.length - 1;
		int i = j - 1;
		while(i > - 1 && arr[i] == arr[j] && (i > 0 && arr[i - 1] == arr[j])) {
			i--;
		}
		
		int prevLeft = i > -1? arr[i] : -1; 
		
		while(i > - 1) {
			System.out.print(String.format("[%s,%s]->(%s,%s);", i, j, arr[i] , arr[j]));
//			System.out.print(String.format("(%s,%s);", arr[i] , arr[j]));
			
			--i;
			while(i > - 1 && arr[i] == prevLeft && (i > 0 && arr[i - 1] == prevLeft)  ) {
				i--;
			}
			
			if (i == -1) {
				int oldJ = j; 
				j--;
				while(j > - 1 && arr[j] == arr[oldJ]) {
					j--;
				}
				if (j == -1) {
					break;
				}
				i = j - 1;
				System.out.println();
				while(i > - 1 && arr[i] == arr[j] && (i > 0 && arr[i - 1] == arr[j])) {
					i--;
				}
				if (i == -1) {
					break;
				}
			}
			
			if (i > -1) {
				prevLeft = arr[i];
			}
		}
	}
}
